$(document).ready(function() {
    $('div#dashboard_map').location_reports_map();
    $('div#dashboard_ff').ff_container();
    $('div#dashboard_connection').connection_container();
    $('div#dashboard_certificate').certificate_container();

    $('div#refresh_all', 'div#dashboard_title').click(function() {
        var url_img_wait = '/images/wait.gif';
        var url_img_refresh = '/images/refresh.png';

        if ($('img', this).attr('src') == url_img_refresh) {
            $('img', this).attr('src', url_img_wait);

            $('img.img_refresh').each(function() {
                $(this).trigger('click');
            });

            $('img', this).attr('src', url_img_refresh);
        }
    });

    $('div#user_delete').html(
        '<a id="user_delete_link" href="/dashboard/user/delete">Delete all stored data!</a>'
    );
    var confirmed = false;
    $('a#user_delete_link').click(function() {
        if (confirmed) {
            return true;
        }
        else {
            $(this).html('Really?');
            $(this).closest('div').append(' <a id="user_delete_link_cancel" href="#">Cancel</a>');

            $('a#user_delete_link_cancel').click(function() {
                confirmed = false;
                $('a#user_delete_link').html('Delete all stored data!');
                $(this).remove();

                return false;
            });
            confirmed = true;
            return false;
        }
    });
});